package hu.myai.indicators.tick;

import hu.myai.api.indicators.AbstractIndicator;
import hu.myai.model.IndicatorVO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Provides rate of the candle body and the shadow. If rising candle the
 * indicator is positive otherwise it is negative. It has predefined parameters.<br>
 * <ul>
 * <li>UPPERSHADOW_TO_ALL
 * <li>SHADOWS_TO_ALL
 * <li>LOWERSHADOW_TO_ALL
 * </ul>
 * 
 * @author bozbalint
 * 
 */
public class TickShadowRateIndicator extends AbstractIndicator {

    /**
     * The object used when logging debug,errors,warnings and info.
     * */
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    public static final double UPPERSHADOW_TO_ALL = 1;
    public static final double SHADOWS_TO_ALL = 0;
    public static final double LOWERSHADOW_TO_ALL = -1;

    public TickShadowRateIndicator(Double parameter) {
        super(parameter);
    }

    @Override
    public void init() {
    }

    @Override
    protected IndicatorVO indicatorCalculation() {

        IndicatorVO indicator = new IndicatorVO();
        indicator.setChanged(true);
        indicator.setDate(lastTick.getTime());

        double value;
        switch (parameter.intValue()) {
        case 1:
            // upper shadow to all
        	value = (lastTick.getHigh() - lastTick.getBodyTop()) / (lastTick.getHigh() - lastTick.getLow());
            break;
        case -1:
            // lower shadow to all
            value = (lastTick.getBodyBottom() - lastTick.getLow())
                    / (lastTick.getHigh() - lastTick.getLow());
            break;
        default:
            // 
            value = (lastTick.getOpen() - lastTick.getClose()) / (lastTick.getHigh() - lastTick.getLow());
        }

        indicator.setValue(value);
        log.debug(indicator.toString());
        return indicator;
    }
}
